package org.noote.libs.widget;

public class Widget_DirectionPad extends Widget_Pad {

	protected boolean _bUpPressed = false;
	protected boolean _bDownPressed = false;
	protected boolean _bRightPressed = false;
	protected boolean _bLeftPressed = false;

	public Widget_DirectionPad(Widget_Window parent) {
		super(parent);
	}
	
	public Widget_DirectionPad(Widget_Window parent, WidgetTheme theme) {
		super(parent, theme);
	}
	
	@Override
	public void create()
	{
		setWorkSpace(0, 0, _theme.padSizeX, _theme.padSizeY);
		setBackground(_theme._textures.getTextureID(WidgetTheme.TEXTID_UDLR));
		setBackgroundColor(_theme.colorLightGray);
	}

	@Override
	protected void _checkButtons()
	{
		super._checkButtons();
		
		_bUpPressed = false;
		_bDownPressed = false;
		_bRightPressed = false;
		_bLeftPressed = false;
		
		if(_iState == TOUCH_MOVED)
			_iState = TOUCH_PRESSED;
		
		if((_iState == TOUCH_RELEASED && _iOldState == TOUCH_PRESSED)
				|| (_iOldState == TOUCH_RELEASED && _iState == TOUCH_PRESSED))
			_bNewEvent = true;
		
		if(_iState == TOUCH_RELEASED) return;

		float fLimitIn = 0.1f;
		float fLimitOut = 0.25f;

        if(_fTouch_X>(0.5f+fLimitIn) && _fTouch_Y>=(0.5f-fLimitOut) && _fTouch_Y<=(0.5f+fLimitOut))
        	_bRightPressed = true; 
		else if(_fTouch_X<(0.5f-fLimitIn) && _fTouch_Y>=(0.5f-fLimitOut) && _fTouch_Y<=(0.5f+fLimitOut))
			_bLeftPressed = true;
		else if(_fTouch_X>=(0.5f-fLimitOut) && _fTouch_X<=(0.5f+fLimitOut) && _fTouch_Y>(0.5f+fLimitIn))
			_bUpPressed = true;
		else if(_fTouch_X>=(0.5f-fLimitOut) && _fTouch_X<=(0.5f+fLimitOut) && _fTouch_Y<(0.5f-fLimitIn))
			_bDownPressed = true;
	}

	public boolean getButtonUp(){return _bUpPressed;}
	public boolean getButtonDown(){return _bDownPressed;}
	public boolean getButtonRight(){return _bRightPressed;}
	public boolean getButtonLeft(){return _bLeftPressed;}
}
